package com.xindz.hgq.database.greendao.bean;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;

import java.io.Serializable;
import java.util.List;


/**
 * @name HGQBase
 * @class name：com.xindz.hgq.database.greendao.bean
 * @describe 学校表 一个学校有很多学生,有很多老师(一对多.一个学校对应多个老师,多个学生)
 * @anthor XINDZ
 * @time 2018/5/21 16:26
 * @change
 * @chang time
 * @class describe
 */
@Entity(active = true,nameInDb = "School")
public class SchoolBean implements Serializable {
    private static final long serialVersionUID = -7021961658843486018L;
    /**
     * 学校主键
     */
    @Id
    @Property(nameInDb = "schoolId")
    private String schoolId;
    /**
     * 学校姓名
     */
    @Property(nameInDb = "schoolName")
    private String schoolName;
    /**
     * 学校所有的老师集合
     */
    @ToMany(referencedJoinProperty = "schoolId")
    private List<TeacherBean> teachers;
    /**
     * 学校所有的学生集合
     */
    @ToMany(referencedJoinProperty = "schoolId")
    private List<StudentBean> students;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 411127457)
    private transient SchoolBeanDao myDao;
    @Generated(hash = 1299678902)
    public SchoolBean(String schoolId, String schoolName) {
        this.schoolId = schoolId;
        this.schoolName = schoolName;
    }
    @Generated(hash = 2040299565)
    public SchoolBean() {
    }
    public String getSchoolId() {
        return this.schoolId;
    }
    public void setSchoolId(String schoolId) {
        this.schoolId = schoolId;
    }
    public String getSchoolName() {
        return this.schoolName;
    }
    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1992569090)
    public List<TeacherBean> getTeachers() {
        if (teachers == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            TeacherBeanDao targetDao = daoSession.getTeacherBeanDao();
            List<TeacherBean> teachersNew = targetDao
                    ._querySchoolBean_Teachers(schoolId);
            synchronized (this) {
                if (teachers == null) {
                    teachers = teachersNew;
                }
            }
        }
        return teachers;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 456331696)
    public synchronized void resetTeachers() {
        teachers = null;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 679127527)
    public List<StudentBean> getStudents() {
        if (students == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            StudentBeanDao targetDao = daoSession.getStudentBeanDao();
            List<StudentBean> studentsNew = targetDao
                    ._querySchoolBean_Students(schoolId);
            synchronized (this) {
                if (students == null) {
                    students = studentsNew;
                }
            }
        }
        return students;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 238993120)
    public synchronized void resetStudents() {
        students = null;
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1561428149)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getSchoolBeanDao() : null;
    }
}
